<?php
/**
 * 文件管理
**/
include("../includes/common.php");
$title='文件管理';
include './head.php';
if($islogin==1){}else loginmsg('请登录后再操作！');
?>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header"><?=$title;?></div>
        <div class="layui-card-body">
			<!-- 表格工具栏 -->
			<form class="layui-form toolbar">
				<div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">选择类型</label>
                        <div class="layui-input-block">
                            <select name="type">
                                <option value="0">全部</option>
                                <option value="1">UID</option>
                                <option value="2">用户名</option>
                        
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
						<label class="layui-form-label w-auto">搜索数据：</label>
						<div class="layui-input-inline mr0">
							<input type="text" name="kw" class="layui-input" placeholder="请输入你所要搜索的内容！" />
						</div>
					</div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索类别</label>
                        <div class="layui-input-block">
                            <select name="method">
                                <option value="0">精确搜索</option>
                                <option value="1">模糊搜索</option>
                            </select>
                        </div>
                    </div>
					<div class="layui-inline">
						<button class="layui-btn icon-btn" lay-filter="roleTbSearch" lay-submit>
							<i class="layui-icon">&#xe615;</i>搜索
						</button>
					</div>
				</div>
			</form>
            <table class="layui-hide" id="userlist" lay-filter="userlist"></table>
            <script id="table_button" type="text/html">
                <a lay-event="edit" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-edit"></i>修改</a>
                <a lay-event="del" class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
                <a lay-event="detail" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-file-b"></i>查看</a>
                
            </script>
        </div>
    </div>
<!-- 修改资源信息 -->
<script type="text/html" id="fileedit">
    <form class="layui-form layui-row model-form" role="form" lay-filter="editform">
        <input type="hidden" name="id" value="" />
        <div class="layui-form-item">
            <label class="layui-form-label">文件名称:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="name" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件类型:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="type" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件大小:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="size2" value="" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件MD5:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="hash" value="" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否隐藏:</label>
            <div class="layui-input-block">
                <select name="hide" class="layui-input">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开启密码:</label>
            <div class="layui-input-block">
                <select name="ispwd" class="layui-input">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下载密码:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="pwd" value="">
            </div>
        </div>
    </form>
</script>


 <!-- 预览模态框 -->
    <div class="preview-modal" id="previewModal">
        <div class="preview-content">
            <span class="close-btn" onclick="closePreview()">&times;</span>
            <div id="previewBody"></div>
        </div>
    </div>

<?php include 'foot.php';?>
<script type="text/javascript">
    layui.use(['layer', 'notice', 'form', 'table', 'element', 'index', 'admin', 'util', 'dropdown'],function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var notice = layui.notice;
        var form = layui.form;
        var table = layui.table;
        var index = layui.index;
        var admin = layui.admin;
        var util = layui.util;
        var dropdown = layui.dropdown;
        var laytpl = layui.laytpl; // 这里加上


        var insTb = table.render({
            elem: '#userlist',
            url: './ajax.php?act=fileList',
            text: {
                none: '哇哦没发现数据哟 T^T ！' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            },
            page: true,
            skin: 'line',
            cellMinWidth: 100,
            limit: 10,
            cols: [[
                {
                    field: 'id',
                    title: 'ID',
                    templet: function(data) {
                        return '<span class="layui-badge layui-badge-blue">'+data.id+'</span>';
                    },
                    width: 85,
                    align: 'center',
                    sort: true
                },
                {
                    field: 'uid',
                    title: 'UID',
                    templet: function(data) {
                        return '<span class="layui-badge layui-badge-blue">'+data.uid+'</span>';
                    },
                    width: 85,
                    align: 'center',
                    sort: true
                },
                {
                    field: 'name',
                    title: '文件名',
                    width: 120,
                    align: 'center',
                    sort: true
			    },
                {
                    field: 'size2',
                    title: '文件大小'
                },
                {
                    field: 'type',
                    title: '文件格式',
                    formatter: function(value, row, index) {
                        return value ? value : '未知';
                    }
                },
                {
                    field: 'addtime',
                    title: '上传日期',
                    width: 150,
                    align: 'center',
                    sort: true
                },
                {
                    field: 'lasttime',
                    title: '上次下载',
                    width: 150,
                    align: 'center',
                    sort: true
                },
                {
                    field: 'ip',
                    title: '上传IP',
                    align: 'center',
                    sort: true
                },
                {
                    field: 'count',
                    title: '下载次数',
                    align: 'center',
                    width: 120,
                    align: 'center',
                    sort: false
                },
                {
                    field: 'block',
                    title: '资源状态',
                    align: 'center',
                    templet: function(data) {
                    if (data.block == 1) {
                        return '<input type="checkbox" name="close" lay-skin="switch" value="' + data.id + '" lay-filter="switchstate" lay-text="正常|禁用" >';
                    } else {
                        return '<input type="checkbox" name="close" lay-skin="switch" value="' + data.id + '" lay-filter="switchstate" lay-text="正常|禁用" checked/>';
                    } 
                 },
                    sort: false
                },
                {
                    field: "action",
                    title: "功能操作",
                    toolbar: "#table_button",
                    align: 'center',
                    width: 300
                }]]
        });

        /* 表格搜索 */
        form.on('submit(roleTbSearch)',function(data) {
            var ii = layer.msg("正在查找数据……", {
                icon: 16
            });
            insTb.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            layer.close(ii);
            return false;
        });
        // 修改状态
        form.on('switch(switchstate)',function(data) {
    		$.ajax({
    			url: './ajax.php?act=setBlock&id=' + data.value,
    			dataType: 'json',
    			success: function(data) {
    				if (data.code == 0) {
    					notice.success({
                            title: '消息通知',
                            message: data.msg,
                            position:'topCenter',
                            audio:''
                        });
    				} else {
                        notice.error({
                            title: '消息通知',
                            message: data.msg,
                            position:'topCenter',
                            audio:''
                        });
    				}
    			}
    		});
    	});

        /* 表格工具栏 */
        table.on('tool(userlist)',function(obj) {
            if (obj.event === "del") {
                layer.confirm('你确实要删除此数据吗？', {
                        btn: ['确定', '取消'],
                        closebtn: 0,
                        icon: 3
                    },
                    function(index) {
                        $.ajax({
                            type: "POST",
                            url: "ajax.php?act=delfile",
                            data: {
                                id: obj.data.id
                            },
                            dataType: "json",
                            success: function(data) {
                                if (data.code == 0) {
                                    insTb.reload();
                                    notice.success({
                                        title: '消息通知',
                                        message: data.msg,
                                        position:'topCenter',
                                        audio:''
                                    });
                                } else {
                                    notice.error({
                                        title: '消息通知',
                                        message: data.msg,
                                        position:'topCenter',
                                        audio:''
                                    });
                                }
                            }
                        });
                        layer.close(index);
                    },function() {});
            }if (obj.event === "edit") {
               admin.open({
                    type: 1,
                    title: '文件信息修改',
                    btn: ['提交', '取消'],
                    content: $('#fileedit').html(),
                    success: function (layero, dIndex) {
                        form.val('editform',obj.data);
                        admin.modelForm(layero, 'edit', 'editform');
                        
                        form.on('submit(edit)', function (data) {
                            notice.msg('正在执行修改中..', {icon: 4, close: true});
                            $.ajax({
                                type: "POST",
                                url: "ajax.php?act=editfile",
                                data: data.field,
                                dataType: "json",
                                success: function(data) {
                                    notice.destroy();
                                    if (data.code == 0) {
                                        insTb.reload();
                                        layer.msg(data.msg, {
            						        icon: 6
            					        });
                                    } else {
                                        layer.msg(data.msg, {
            						        icon: 5
            					        });
                                    }
                                }
                            });
                            return false;
                        });
                        
                    }
                });
            } if (obj.event === "detail") {
                window.location.href = obj.data.pageurl;
            }
        });
    });


    
</script>
</body>
</html>